﻿Public Class ViewTableViewerFilter

    Sub New()

        ' Cet appel est requis par le concepteur.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        'AddHandler LstValues.ItemContainerGenerator.StatusChanged, AddressOf LstValuesItemContainerGeneratorStatusChanged
    End Sub
    Private Sub BtAnnuler_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtAnnuler.Click
        Windows.Window.GetWindow(Me).Close()
    End Sub

    Private Sub BtInverser_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtInverser.Click
        Dim lst = If(rbtVisibles.IsChecked, LstValues, LstAllValues)

        If lst.SelectedItems.Count = 0 Then Return
        If lst.SelectedItems.Count = LstValues.Items.Count Then Return

        For Each item In lst.ItemsSource
            Dim lstitem As Windows.Controls.ListBoxItem = lst.ItemContainerGenerator.ContainerFromItem(item)
            lstitem.IsSelected = Not lstitem.IsSelected
        Next
    End Sub

    Private Sub BtValider_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtValider.Click
        Dim filter As ViewModelTableViewerFilter = DataContext
        Dim lst = If(rbtVisibles.IsChecked, LstValues, LstAllValues)

        filter.Selecteds = lst.SelectedItems.Cast(Of Object).ToList()
        Windows.Window.GetWindow(Me).Close()
    End Sub

    Private Sub LstValuesItemContainerGeneratorStatusChanged(sender As Object, e As EventArgs)
        'If LstValues.ItemContainerGenerator.Status = Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated Then
        '    Dim filter As ViewModelTableViewerFilter = DataContext

        '    If filter.Selecteds.Count = 0 Then Return

        '    For Each item In filter.Selecteds
        '        Dim lstitem As Windows.Controls.ListBoxItem = LstValues.ItemContainerGenerator.ContainerFromItem(item)
        '        lstitem.IsSelected = True
        '        ' lstitem.SetValue(Windows.Controls.ListBox.IsSelectionActiveProperty, True)
        '    Next
        'End If
    End Sub

End Class
